Is this buffer overflow working on Mac OSX? [migrated]

Posted by cobie on Programmers See other posts from Programmers or by cobie
Published on 2012-06-15T21:04:21Z Indexed on 2012/06/16 3:23 UTC
Read the original article Hit count: 189

Filed under:
|

Was reading through some text and playing around with attempting to write past the size of an array in C i.e buffer overflow. The text indicates that whenever you attempt to write to say array[5] when the length of the array is 5 then you get a segmentation fault but I dont seem to be getting that When using the code below. The code actually runs.

#include <stdio.h>
#include <string.h>

int main ()
{
    int i;
    int array[5] = {1, 2, 3, 4, 5};
    for (i = 0; i <= 255; i++)
    {
        array[i] = 10;
    }
    int len = sizeof(array) / sizeof(int);
    printf("%d\n", len);
    printf("%d\n", array[254]);
}

On execution of the last statement, a 10 is printed. Am wondering whether this is a vulnerability or if there is something I am missing. I am running the code from iterm2 on a macbook pro.

© Programmers or respective owner

Related posts about c

    Related posts about security